//兑换中心
let $productExchangeSource = $("#productExchangeSource");
let $productExchangeTarget = $("#productExchangeTarget");
let $memberProductTable = $("#memberProductTable");
let $noMemberProductTable = $("#noMemberProductTable");
let productTargetData=[];//要兑换的产品数据
let memberData=[],noMemberData=[];
//防止表头与表格不对齐
$(window).resize(function () {
    $productExchangeSource .bootstrapTable('resetView');
    $productExchangeTarget.bootstrapTable('resetView');
    $memberProductTable.bootstrapTable('resetView');
    $noMemberProductTable.bootstrapTable('resetView');
});
function getMemberData(){
    $.ajax({
        url: '/csd/productManager/selectExchangeCustomerMemberProductList',
        type: 'POST',
        /*data:{productCategories:'1'},*/
        dataType: "json",
        async:false,
        success: (function (data) {
            if (data.code == '000000') {
                memberData=data.data;
            }
        }),
        error: (function () {
            $.alert({
                title:'提示',
                content:"请求失败"
            });
        })
    })
}
function getNoMemberData(){
    $.ajax({
        url: '/csd/productManager/selectExchangeCustomerProductList',
        type: 'POST',
        /*data:{productCategories:'0'},*/
        dataType: "json",
        async:false,
        success: (function (data) {
            if (data.code == '000000') {
                noMemberData=data.data;
            }
        }),
        error: (function () {
            $.alert({
                title:'提示',
                content:"请求失败"
            });
        })
    })
}
function getProductExchangeTarget(){
    $.ajax({
        url: '/csd/productManager/selectProductExchangeFormList',
        type: 'POST',
        data:{orderNumber:$.trim($("#orderNumberText").text())},
        dataType: "json",
        async:false,
        success: (function (data) {
            if (data.code == '000000') {
                productTargetData=data.data;
            }
        }),
        error: (function () {
            $.alert({
                title:'提示',
                content:"请求失败"
            });
        })
    })
}
$(function () {
    setTimeout(function(){
        productExchangeFormValidator();
        exchangeReasonFormValidator();
        getMemberData();
        getNoMemberData();
    },100)

})
$("#addProductModal").on('hide.bs.modal', function () {
    getMemberData();
    getNoMemberData();
})


//兑换明细页面下的方法

window.operateEvents = {
    'click #delete': function (e, value, row, index) {
        $.confirm({
            title: '提示',
            content: `是否确认删除`,
            buttons: {
                confirm: {
                    text: '确认',
                    btnClass: 'btn-primary',
                    action: function () {
                        deleteProduct(row)
                    }
                },
                cancel: {
                    text: '取消',
                    btnClass: 'btn-primary',
                    action: function () {
                        return;
                    }
                }
            }
        });

    }
}
function deleteProduct(row){
    $.ajax({
        url: '/csd/productManager/deleteProductExchangeFormBy',
        type: 'POST',
        data:{
            productExchangeId:row.productExchangeId,
            delFlag:row.delFlag
        },
        dataType: 'json',
        async : false,
        success:(function(data) {
            if(data.code=='000000'){
                if(data.data.code==0){
                    $.alert(
                        {
                            title:'提示',
                            content:"删除成功！"
                        }
                    );
                    getProductExchangeTarget();
                    tableListClient('productExchangeTarget',exchangedProductColumns,productTargetData)
                }else{
                    $.alert({
                        title: '提示',
                        content: data.data.msg,
                    });
                }
            }else{
                $.alert(
                    {
                        title:'提示',
                        content:'请求错误'
                    }

                );
            }

        })
    });
}

//产品兑换部分方法
// 重置上传模块
function uploadReset() {
    $('#importInput').val('');
    $('#nameText').html('点击选择模板');
}
//上传附件
function uploadImg() {
    var $fileUpLoadExchange=$("#importInput");
    var $fileDom = $('#exchangeContractPic');
    let fileToUpLoad = $fileUpLoadExchange.prop('files')[0];
    // 功能：合同附件点取消按钮清空文件域内容
    if (!fileToUpLoad) {
        $fileDom.val('');
        return;
    }
    // 功能：限制上传文件大小为2M内
    if (fileToUpLoad && fileToUpLoad.size > 1 * 1024 * 1024) {
        $.alert('附件最大为2M，请重新选择！', function () {
            $fileUpLoadExchange.val('');
            $fileDom.val('');
        });
        return;
    }
    var formFile = new FormData();
    formFile.append("file", fileToUpLoad);
    $("#nameText").html( fileToUpLoad.name);
    var data = formFile;
    var imgId;
    $.ajax({
        url: '/file/uploadByOneFile',
        data: data,
        type: "POST",
        dataType: "json",
        async: false,
        cache: false,
        processData: false,
        contentType: false,
        success: function (data) {
            if (data.code == "000000") {
                $fileDom.val(data.data.fileId)
                imgId = data.data.fileId;
            }
        },
        error: (function (res) {
            $.alert({
                title:'提示',
                content:res
            })
        })
    });
    return imgId;
}
function tableList(domId,url,columns,queryParams) {
    $(`#${domId}`).bootstrapTable('destroy');
    $(`#${domId}`).bootstrapTable({
        classes: 'table table-bordered table-hover table-striped',
        url: url,
        method: 'get',                                      // 请求方式
        contentType: 'application/x-www-form-urlencoded',   // 请求内容类型
        dataType: 'json',                                   // 数据类型
        striped: true,                                      // 是否显示行间隔色
        sortable: true,                                     // 是否启用排序
        sortOrder: 'desc',                                  // 排序方式
        sortName: 'createTm',                               // 排序字段
        cache: false,                                       // 是否使用缓存
        showColumns: false,                                 // 显示隐藏列
        showRefresh: false,                                 // 显示刷新按钮
        showToggle: false,                                  // 切换显示样式
        showFooter: false,                                  // 显示Table脚部
        pagination: true,                                   // 是否显示分页
        showPaginationSwitch: false,                        // 是否显示分页按钮
        clickToSelect: false,                                // 是否启用点击选中行
        maintainSelected: true,                             // 分页是否保留选中
        singleSelect: false,
        undefinedText: '-',                                 // cell没有值时显示
        sidePagination: 'server',                           // 分页方式：client客户端分页，server服务端分页
        uniqueId: 'finishOrderProductId',
        idField: 'finishOrderProductId',
        serverSelected: true,// 开启后端分页记住已选项功能
        serverSelectedField: 'finishOrderProductId',// 已选项的唯一识别主键
        pageSize: 10,//每页的记录行数
        pageNumber: 1,//初始化加载第1页，默认第1页
        pageList: [10,15,20],//可供选择的每页的行数
        fixedColumns: true,     // 冻结列
        fixedNumber: 1,         // 左侧固定列
        fixedRightNumber:1,    // 右侧固定列
        queryParams: queryParams,  // 查询参数
        columns: columns,
        responseHandler: function (result) {
            if (result.code == "000000") {
                if(result.data.constructor===Object){
                    if(result.data.code=='1'){
                        $.alert({
                            title:'提示',
                            content:result.data.msg
                        });
                        var obj = {
                            "total": 0,
                            "rows": [],
                        }
                    }
                }else{
                    var obj = {
                        "rows": result.data,
                        "total": result.totalRecords//总条数
                    };
                }


            } else {
                var obj = {
                    "total": 0,
                    "rows": [],
                }
            }
            return obj;
        },
        onLoadSuccess: function (data) {
            // console.log(data)
        },
        onLoadError: function (status) {
            if (status == 403) {
                $.alert(
                    {
                        title:'提示',
                        content:"权限不足！禁止访问！"
                    }
                );
            } else {
                //加载失败时执行
                $.alert(
                    {
                        title:'提示',
                        content:"加载失败！"
                    }
                );
            }
        },
        formatLoadingMessage: function () {
            return "请稍等，加载中...";
        },
        formatNoMatches: function () {
            return '无符合条件的记录';
        },
    });

}
function tableListClient(domId,columns,data) {
    $(`#${domId}`).bootstrapTable('destroy');
    $(`#${domId}`).bootstrapTable({
        data:data,
        dataType: 'json',                                   // 数据类型
        striped: true,                                      // 是否显示行间隔色
        sortable: true,                                     // 是否启用排序
        sortOrder: 'desc',                                  // 排序方式
        sortName: 'createTm',                               // 排序字段
        cache: false,                                       // 是否使用缓存
        showColumns: false,                                 // 显示隐藏列
        showRefresh: false,                                 // 显示刷新按钮
        showToggle: false,                                  // 切换显示样式
        showFooter: false,                                  // 显示Table脚部
        pagination: true,                                   // 是否显示分页
        showPaginationSwitch: false,                        // 是否显示分页按钮
        clickToSelect: false,                                // 是否启用点击选中行
        maintainSelected: true,                             // 分页是否保留选中
        singleSelect: false,
        undefinedText: '-',                                 // cell没有值时显示
        sidePagination: 'client',                           // 分页方式：client客户端分页，server服务端分页
        uniqueId: 'changeCourseId',
        idField: 'changeCourseId',
        serverSelected: false,// 开启后端分页记住已选项功能
        serverSelectedField: 'changeCourseId',// 已选项的唯一识别主键
        pageSize: 10,//每页的记录行数
        pageNumber: 1,//初始化加载第1页，默认第1页
        pageList: [10,15,20],//可供选择的每页的行数
        fixedColumns: true,     // 冻结列
        fixedNumber: (domId=='memberProductTable'||domId=='noMemberProductTable')?0:1,         // 左侧固定列
        fixedRightNumber:1,    // 右侧固定列
        columns: columns,
        responseHandler: function (result) {
            if (result.code == "000000") {
                if(result.data.constructor===Object){
                    $.alert({
                        title:'提示',
                        content:result.data.msg
                    });

                    var obj = {
                        "total": 0,
                        "rows": [],
                    }
                    if(domId=='productExchangeTarget'){
                        productTargetData=[];
                    }
                }else{
                    var obj = {
                        "rows": result.data,
                        "total": result.totalRecords//总条数
                    };
                    if(domId=='productExchangeTarget'){
                        productTargetData=result.data;
                    }
                }

            } else {
                var obj = {
                    "total": 0,
                    "rows": [],
                }
                if(domId=='productExchangeTarget'){
                    productTargetData=[];
                }
            }
            return obj;
        },
        onCheck:function(row,$element){
            if (domId=='memberProductTable'||domId=='noMemberProductTable'){
                var index=$element.data('index')
                $(`#${domId}`).bootstrapTable('updateRow',{index:index,row:row})
            }

        },
        onUncheck:function(row,$element){
            if (domId=='memberProductTable'||domId=='noMemberProductTable'){
                var index=$element.data('index')
                $(`#${domId}`).bootstrapTable('updateRow',{index:index,row:row})
            }
        },
        onLoadSuccess: function (data) {
            // console.log(data)
        },
        onLoadError: function (status) {
            if (status == 403) {
                $.alert(
                    {
                        title:'提示',
                        content:"权限不足！禁止访问！"
                    }
                );
            } else {
                //加载失败时执行
                $.alert(
                    {
                        title:'提示',
                        content:"加载失败！"
                    }
                );
            }
        },
        formatLoadingMessage: function () {
            return "请稍等，加载中...";
        },
        formatNoMatches: function () {
            return '无符合条件的记录';
        },
    });

}
//订单编号校验
function productExchangeFormValidator(){
    $('#productExchangeForm').bootstrapValidator({
        fields: {
            orderNumber: {
                validators: {
                    notEmpty: {
                        message: '订单编号不能为空'
                    }
                }
            }
        }
    })
}
function exchangeReasonFormValidator(){
    $('#exchangeReasonForm').bootstrapValidator({
        fields: {
            reason: {
                validators: {
                    notEmpty: {
                        message: '兑换原因不能为空'
                    },
                    stringLength: {
                        min:30,
                        message: '兑换原因不少于30字'
                    }
                }
            }
        }
    })
}
function openAddProductModal(){
    let productSource=$productExchangeSource.bootstrapTable("getServerSelected", true);
    if(productSource.length==0){
        $.alert(
            {
               title:'提示',
               content:'请选择产品'
            }

        );
        return;
    }
    let productTotalPrice=getTotalPrice(productSource,'productFinalPrice');//兑换产品的总价格
    let alreadyExchangeProductTotalPrice=getTotalPrice(productTargetData,'price');//已经存在的添加产品总价格
    if(productTotalPrice>alreadyExchangeProductTotalPrice){
        $("#addProductModal").modal('show');
        $("#memberProductTab").click();
        tableListClient('memberProductTable',addMemberProductColumns,memberData);
        tableListClient('noMemberProductTable',addNoMemberProductColumns,noMemberData)
    }else{
        if(productTotalPrice<alreadyExchangeProductTotalPrice){
            var content='产品总价格是:'+productTotalPrice+',添加的要兑换产品总价格是:'+alreadyExchangeProductTotalPrice+',要兑换的产品总价格不能大于产品总价格';
            $.alert(
                {
                    title:'提示',
                    content:content
                }

            );
        }else{
            var content='要兑换的产品总价格已经等于产品总价格了';
            $.alert(
                {
                    title:'提示',
                    content:content
                }

            );
        }

    }
}
/**
 * --列表序列号
 */
function indexFormat(value, row, index) {
    return index + 1;
}
function operateIndexFormat(value, row, index) {
    var html = '<button type="button" class="btn btn-default btn-danger" id="delete"><i class="mdi mdi-delete"></i>删除</button>';
    return html;
}
function operateMemberInputFormat(value, row, index) {
    var price=(!row.price && typeof(row.price)!="undefined" && row.price!=0)?'':row.price;
    var selectFlag = row[3]?true:false;
    if(Number(price)>0&&selectFlag){
        var html = '<input class="form-control" readonly type="text" placeholder="请输入价格" value="'+price+'" onblur="changeMemberData('+index+',this)">';
    }else{
        var html = '<input class="form-control" type="text" placeholder="请输入价格" value="'+price+'" onblur="changeMemberData('+index+',this)">';
    }
    return html;
}
function operateNoMemberInputFormat(value, row, index) {
    var price=(!row.price && typeof(row.price)!="undefined" && row.price!=0)?'':row.price;
    var selectFlag = row[3]?true:false;
    if(Number(price)>0&&selectFlag){
        var html = '<input class="form-control" type="text" readonly placeholder="请输入价格" value="'+price+'" onblur="changeNoMemberData('+index+',this)">';
    }else{
        var html = '<input class="form-control" type="text" placeholder="请输入价格" value="'+price+'" onblur="changeNoMemberData('+index+',this)">';
    }
    return html;
}
function changeMemberData(index,obj){
    var value = $(obj).val();
    var row = $("#memberProductTable").bootstrapTable('getData')[index];
    row['price'] = value;
    $("#memberProductTable").bootstrapTable('updateRow',{index:index,row:row})
}
function changeNoMemberData(index,obj){
    var value = $(obj).val();
    var row = $("#noMemberProductTable").bootstrapTable('getData')[index];
    row['price'] = value;
    $("#noMemberProductTable").bootstrapTable('updateRow',{index:index,row:row})
}
let productParams=function(params){
    params.pageSize = params.limit;
    params.pageIndex = (params.offset / params.limit) + 1;
    params.sortName = params.sort;
    params.sortOrder = params.order;
    params.orderNumber = $.trim($("#orderNumberText").text());
    return params
}
let productColumns=[
    {title: '序号', field: 'index', align: 'center', valign: 'left', formatter: indexFormat},
    {title: '产品名称',field: 'productName', align: 'left', valign: 'middle'},
    {title: '产品号',field: 'finishOrderProductNum', align: 'left', valign: 'middle'},
    {title: '产品成交价',field: 'productFinalPrice', align: 'left', valign: 'middle'},
    {title: '操作',checkbox: true, visible: true}
]
let exchangedProductColumns=[
    {title: '序号', field: 'index', align: 'center', valign: 'left', formatter: indexFormat},
    {title: '产品名称',field: 'productName', align: 'left', valign: 'middle'},
    {title: '产品原价',field: 'productOriginalPrice', align: 'left', valign: 'middle',formatter:function(value){
            if(!value&&value!==0){
                return '-'
            }else{
                return value
            }
        }},
    {title: '产品单价',field: 'productUnitPrice', align: 'left', valign: 'middle',formatter:function(value){
            if(!value&&value!==0){
                return '-'
            }else{
                return value
            }
        }},
    {title: '产品会员价',field: 'productMemberPrice', align: 'left', valign: 'middle',formatter:function(value){
            if(!value&&value!==0){
                return '-'
            }else{
                return value
            }
        }},
    {title: '定价价格',field: 'price', align: 'left', valign: 'middle',formatter:function(value){
            if(!value&&value!==0){
                return '-'
            }else{
                return value
            }
        }},
    {title: '会员售价价格',field: 'sellingCardPrice', align: 'left', valign: 'middle',formatter:function(value){
            if(!value&&value!==0){
                return '-'
            }else{
                return value
            }
        }},
    {title: '操作',field: 'operate', align: 'right', valign: 'middle',events:operateEvents, formatter: operateIndexFormat}
]
let addMemberProductColumns=[
    {title: '产品编号',field: 'memberProductCode', align: 'left', valign: 'middle'},
    {title: '产品名称',field: 'memberCardName', align: 'left', valign: 'middle'},
    {title: '输入价格',field: 'price', align: 'left', valign: 'middle',width:200,formatter: operateMemberInputFormat},
    {title: '操作',checkbox: true, visible: true,width:60,formatter:function(value,row,index){//设置满足条件的行可以使用复选框
            if((!row.price && typeof(row.price)!="undefined"&& row.price!=0)||row.price<=0){
                return {
                    disabled : true
                }
            }

        }}
]
let addNoMemberProductColumns=[
    {title: '产品编号',field: 'productCode', align: 'left', valign: 'middle'},
    {title: '产品名称',field: 'productName', align: 'left', valign: 'middle'},
    {title: '输入价格',field: 'price', align: 'left', valign: 'middle',width:200,formatter: operateNoMemberInputFormat},
    {title: '操作',checkbox: true, visible: true,width:60,formatter:function(value,row,index){//设置满足条件的行可以使用复选框
            if((!row.price && typeof(row.price)!="undefined"&& row.price!=0)||row.price<=0){
                return {
                    disabled : true
                }
            }

        }}
]
function searchOrder(){
    var bootstrapValidator = $("#productExchangeForm").data('bootstrapValidator');
    bootstrapValidator.validate();
    if (!bootstrapValidator.isValid()) {
        return;
    }
    var reasonFormValidator = $("#exchangeReasonForm").data('bootstrapValidator');
    if (reasonFormValidator) {
        $("#exchangeReasonForm").data('bootstrapValidator').destroy();
        $('#exchangeReasonForm').data('bootstrapValidator', null);
    }
    exchangeReasonFormValidator()
    $("#reason").val('');
    uploadReset();
    $("#reason").removeAttr("readonly");
    $("#importTemplate").css({'pointer-events':'auto',cursor: 'pointer'});
    $("#productList").show();
    $("#orderNumberText").text($.trim($("#orderNumber").val()));
    getProductExchangeTarget();
    tableList('productExchangeSource','/csd/productManager/selectExchangeOrderProductList',productColumns,productParams);
    tableListClient('productExchangeTarget',exchangedProductColumns,productTargetData);
}
// 解决table中点击行选中与checkbox冲突问题
$('table').on('load-success.bs.table', function (e,data) {
    $(e.target).find('label.lyear-checkbox').on('click', function (e) {
        e.stopPropagation();
    })
});

//数组转字符串
function getDataStr(data,fileName){
    let arr=[];
    data.filter((item)=>{
        arr.push(item[fileName])
    })
    return arr.join()

}
function getTotalPrice(data,fileName){
    let totalPrice=0;
    data.filter((item)=>{
        totalPrice+=Number(item[fileName])
    });
    return totalPrice;
}
function addProduct(){
    let productSource=$productExchangeSource.bootstrapTable("getServerSelected", true);//选中的产品
    let productTotalPrice=getTotalPrice(productSource,'productFinalPrice');//兑换产品的总价格
    let alreadyExchangeProductTotalPrice=getTotalPrice(productTargetData,'price');//已经存在的添加产品总价格

    /*let memberTableList = $memberProductTable.bootstrapTable('getAllSelections');*/
    let memberTableList = $memberProductTable.bootstrapTable('getAllSelections');
    let noMemberTableList = $noMemberProductTable.bootstrapTable('getAllSelections');
    let addProductList = memberTableList.concat(noMemberTableList);

    let addProductTotalPrice=getTotalPrice(addProductList,'price');//正在添加的产品总价格
    if(productTotalPrice!=(alreadyExchangeProductTotalPrice+addProductTotalPrice)){
        var content='产品总价格是:'+productTotalPrice+',已经添加过的要兑换产品总价格是:'+alreadyExchangeProductTotalPrice+',正在添加的要兑换产品总价格是:'+addProductTotalPrice+',产品总价格和要兑换的产品总价格不相等';
        $.alert(
            {
                title:'提示',
                content:content
            }

        );
        return;
    }
    if(addProductList.length==0){
        $.alert({
            title: '提示',
            content: '请选择要添加的产品!',
        });
        return;
    }
    var params={
        orderNumber:$.trim($("#orderNumberText").text()),
        /*productName:getDataStr(addProductList,'productName'),
        productOriginalPrice:getDataStr(addProductList,'productOriginalPrice'),
        productUnitPrice:getDataStr(addProductList,'productUnitPrice'),
        productMemberPrice:getDataStr(addProductList,'productMemberPrice'),
        finishOrderProductId:getDataStr(addProductList,'finishOrderProductId'),
        price:getDataStr(addProductList,'price')*/
        memberProductList:memberTableList,
        list:noMemberTableList
    };
    $.ajax({
        url: '/csd/productManager/addProductExchangeform',
        type: 'POST',
        dataType: "json",
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify(params),
        success: (function (data) {
            if (data.code == '000000') {
                $.alert(
                    {
                        title:'提示',
                        content:'添加成功'
                    }
                );
                $("#addProductModal").modal('hide');
                getProductExchangeTarget();
                tableListClient('productExchangeTarget',exchangedProductColumns,productTargetData)
            }
        }),
        error: (function () {
            $.alert(
                {
                    title:'提示',
                    content:'请求失败'
                }
            );
        })
    })

}

//提交审核
function submitExamine(){
    let productSource=$productExchangeSource.bootstrapTable("getServerSelected", true);
    if(productSource.length==0){
        $.alert(
            {
                title:'提示',
                content:'请选择产品'
            }
        );
        return;
    }
    if(productTargetData.length==0){
        $.alert(
            {
                title:'提示',
                content:"请添加要兑换的产品"
            }
        );
        return;
    }
    let productTotalPrice=getTotalPrice(productSource,'productFinalPrice');//兑换产品的总价格
    let alreadyExchangeProductTotalPrice=getTotalPrice(productTargetData,'price');//已经存在的添加产品总价格
    if(productTotalPrice!=alreadyExchangeProductTotalPrice){
        var content='兑换产品总价格是:'+productTotalPrice+',添加的要兑换产品总价格是:'+alreadyExchangeProductTotalPrice+',产品总价格和要兑换的产品价格不相等'
        $.alert(
            {
                title:'提示',
                content:content
            }
        );
        return;
    }
    var bootstrapValidator = $("#exchangeReasonForm").data('bootstrapValidator');
    bootstrapValidator.validate();
    if (!bootstrapValidator.isValid()) {
        return;
    }
    var params={
        orderNumber:$.trim($("#orderNumberText").text()),
        remarks:$.trim($("#reason").val()),
        uploadId:$('#exchangeContractPic').val(),
        productExchangeApprovalList:productTargetData,
        finishOrderProductList:productSource,
        contractNumber:productSource[0]['contractNumber'],
        customerName:productSource[0]['customerName'],
        productStatus:productSource[0]['productStatus']
        /*//要兑换产品列表
        productName:getDataStr(productTargetData,'productName'),
        productOriginalPrice:getDataStr(productTargetData,'productOriginalPrice'),
        productUnitPrice:getDataStr(productTargetData,'productUnitPrice'),
        productMemberPrice:getDataStr(productTargetData,'productMemberPrice'),
        price:getDataStr(productTargetData,'price'),
        productExchangeId:getDataStr(productTargetData,'productExchangeId'),
        finishOrderProductId:getDataStr(productTargetData,'finishOrderProductId'),
        //兑换产品列表
        exchangeProductName:getDataStr(productSource,'exchangeProductName'),
        exchangeFinishOrderProductId:getDataStr(productSource,'exchangeFinishOrderProductId'),
        productFinalPrice:getDataStr(productSource,'productFinalPrice'),
        finishOrderProductNum:getDataStr(productSource,'finishOrderProductNum'),
        //兑换产品列表
        contractNumber:productSource[0]['contractNumber'],
        customerName:productSource[0]['customerName'],
        productStatus:productSource[0]['productStatus']*/
    }
    $.ajax({
        url: '/csd/productManager/addProductExchangeApproval',
        type: 'POST',
        dataType: "json",
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify(params),
        success: (function (data) {
            if (data.code == '000000') {
                $.alert({
                    title:'提示',
                    content:"提交成功"
                });
                $("#productExchangeBtn").hide();
                $("#reason").attr('readonly','readonly');
                $("#importTemplate").css({'pointer-events':'none',cursor: 'not-allowed'});
            }
        }),
        error: (function () {
            $.alert({
                title:'提示',
                content:"请求失败"
            });
        })
    })


}
//提交审核成功
function examineFinish(){
//清除已有校验
    var bootstrapValidator = $("#productExchangeForm").data('bootstrapValidator');
    if (bootstrapValidator) {
        $("#productExchangeForm").data('bootstrapValidator').destroy();
        $('#productExchangeForm').data('bootstrapValidator', null);
    }
    $("#orderNumber").val("");
    productExchangeFormValidator();
}
//取消
function cancel(){
    examineFinish();
    $("#productList").hide();
    $.ajax({
        url: '/csd/productManager/deleteRroductExchangeForm',
        type: 'POST',
        data:{
            productExchangeId:getDataStr(productTargetData,'productExchangeId')
        },
        dataType: "json",
        async:false,
        success: (function (data) {
            console.log(data.message)
        }),
        error: (function () {
            $.alert({
                title:'提示',
                content:"请求失败"
            });

        })
    })

}



